package snapex.user.mapper;

import org.apache.ibatis.builder.annotation.ProviderMethodResolver;

public class UserSqlProvider implements ProviderMethodResolver {
	
	public static String selectAuthorityByUsername(String username) {
		
		StringBuilder sql = new StringBuilder();
		sql.append(" select rr.resource_code from role_resource rr") 
			.append(" where exists (")
			.append(" select 1 from user_group_role ugr") 
			.append(" where rr.role_code=ugr.role_code") 
			.append(" and ugr.user_group_code in (")
			.append("	select ugm.user_group_code from user_group_member ugm") 
			.append("	where exists (select 1 from user u where ugm.user_id=u.user_id and u.username=#{value})")
			.append(" )")
			.append(")");
		
		return sql.toString();
	}	
	
	
	public static String selectAuthorityByHashKey(String wechatKey) {
		
		StringBuilder sql = new StringBuilder();
		sql.append(" select rr.resource_code from role_resource rr") 
			.append(" where exists (")
			.append(" select 1 from user_group_role ugr") 
			.append(" where rr.role_code=ugr.role_code") 
			.append(" and ugr.user_group_code in (")
			.append("	select ugm.user_group_code from user_group_member ugm") 
			.append("	where exists (select 1 from user u where ugm.user_id=u.user_id and u.wechat_key=#{value})")
			.append(" )")
			.append(")");
		
		return sql.toString();
	}
}
